package svc.elib.analysis;

import java.io.IOException;
import java.util.LinkedList;

import svc.elib.db.Database;
import svc.elib.socnet.ConnectedComponents;
import svc.elib.socnet.JournalFilter;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;
import svc.elib.socnet.JournalFilter.JournalNet;

public class JournalStatistics {

	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		ConnectedComponents cn = new ConnectedComponents(net);
		cn.resolveComponents();
		
		/*
		StringBuilder sb = new StringBuilder();
		sb.append("ELIB").append(",");
		sb.append(db.getNumPapers()).append(",");
		sb.append(db.getFirstYear()).append(",");
		sb.append(net.getNumNodes()).append(",");
		sb.append(net.getNumMaleAuthors()).append(",");
		sb.append(net.getNumFemaleAuthors()).append(",");
		sb.append(net.getNumLinks()).append(",");
		sb.append(net.getNumIsolated()).append(",");
		int lifeTime = db.getLastYear() - db.getFirstYear() + 1;
		sb.append(lifeTime).append(",");
		sb.append(cn.getNumComponents()).append(",");
		sb.append(cn.avgComponentSize()).append(",");
		sb.append(cn.avgComponentDensity()).append(",");
		sb.append(net.getDensity()).append(",");
		sb.append(net.getDiameter()).append(",");
		sb.append(net.getSW()).append(",");
		sb.append(net.getCC());
		*/
		
		
		
		StringBuilder sb = new StringBuilder();
		sb.append("ELIB").append(" $ ");
		sb.append(db.getNumPapers()).append(" $ ");
		sb.append(net.getNumNodes()).append(" $ ");
		sb.append(net.getNumLinks()).append(" $ ");
		sb.append(net.numIsolatedFrac()).append(" $ ");
		sb.append(net.maleFemaleRatio()).append(" $ ");
		sb.append(cn.getNumComponents()).append(" $ ");
		sb.append(cn.getLargestComponentSize()).append(" $ ");
		sb.append(net.getSW3()).append(" $ ");
		sb.append(net.getDiameter()).append(" $ ");
		sb.append(net.getCC()).append(" \\\\ ");
		
		
		System.out.println(sb.toString());
	
		JournalFilter jf = new JournalFilter(db);
		
		LinkedList<JournalNet> jNets = jf.getJournalNets();
		for (JournalNet jn : jNets) {
			net = jn.getNet();
			db = jn.getDb();
			
			cn = new ConnectedComponents(jn.getNet());
			cn.resolveComponents();
			sb = new StringBuilder();
			
			sb.append(db.getName()).append(" $ ");
			sb.append(db.getNumPapers()).append(" $ ");
			sb.append(net.getNumNodes()).append(" $ ");
			sb.append(net.getNumLinks()).append(" $ ");
			sb.append(net.numIsolatedFrac()).append(" $ ");
			sb.append(net.maleFemaleRatio()).append(" $ ");
			sb.append(cn.getNumComponents()).append(" $ ");
			sb.append(cn.getLargestComponentSize()).append(" $ ");
			sb.append(net.getSW3()).append(" $ ");
			sb.append(net.getDiameter()).append(" $ ");
			sb.append(net.getCC()).append(" \\\\ ");
			
			/*
			sb.append(db.getNumPapers()).append(",");
			sb.append(db.getFirstYear()).append(",");
			sb.append(net.getNumNodes()).append(",");
			sb.append(net.getNumMaleAuthors()).append(",");
			sb.append(net.getNumFemaleAuthors()).append(",");
			sb.append(net.getNumLinks()).append(",");
			sb.append(net.getNumIsolated()).append(",");
			lifeTime = db.getLastYear() - db.getFirstYear() + 1;
			sb.append(lifeTime).append(",");
			sb.append(cn.getNumComponents()).append(",");
			sb.append(cn.avgComponentSize()).append(",");
			sb.append(cn.avgComponentDensity()).append(",");
			sb.append(net.getDensity()).append(",");
			sb.append(net.getDiameter()).append(",");
			sb.append(net.getSW()).append(",");
			sb.append(net.getCC());
			*/
			System.out.println(sb.toString());
		}
	}
}
